//
//  HNSH_LogisticsTopView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/1.
//

#import "HNSH_LogisticsTopView.h"

@interface HNSH_LogisticsTopView ()
/**  */
@property (nonatomic, strong)UIView * segView;
/**  */
@property (nonatomic, strong)UIView * bgView;
/**  */
@property (nonatomic, strong)UIImageView * imgView;
/**  */
@property (nonatomic, strong)UILabel * statusLabel;
/**  */
@property (nonatomic, strong)UILabel * companyLabel;
/**  */
@property (nonatomic, strong)UILabel * orderNoLabel;
/**  */
@property (nonatomic, strong)UIView * secSegView;
/**  */
@property (nonatomic, strong)UILabel * titleLabel;
@end

@implementation HNSH_LogisticsTopView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}

//MARK: Cycle Methods
- (void)addAllViews{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.segView];
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.imgView];
    [self.bgView addSubview:self.statusLabel];
    [self.bgView addSubview:self.companyLabel];
    [self.bgView addSubview:self.orderNoLabel];
    [self addSubview:self.secSegView];
    [self addSubview:self.titleLabel];
}

- (void)addAllLayout{
    [self.segView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(4);
    }];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.segView.mas_bottom);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(112);
    }];
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.bgView);
        make.left.mas_equalTo(16);
        make.width.height.mas_equalTo(80);
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imgView.mas_right).offset(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.imgView);
        make.height.mas_equalTo(17);
    }];
    [self.companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.statusLabel);
        make.top.mas_equalTo(self.statusLabel.mas_bottom).offset(4);
        make.height.mas_equalTo(17);
    }];
    [self.orderNoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.statusLabel);
        make.top.mas_equalTo(self.companyLabel.mas_bottom).offset(4);
        make.height.mas_equalTo(17);
    }];
    [self.secSegView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.bgView.mas_bottom);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(8);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.height.mas_equalTo(50);
        make.top.mas_equalTo(self.secSegView.mas_bottom);
    }];
}

//MARK: Setter Methods
- (void)setOrderModel:(HNSH_OrderListModel *)orderModel{
    _orderModel = orderModel;

    HNSH_ConfirmOrderGoodsModel *specModel = orderModel.items[0];
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:specModel.left_icon] placeholderImage:[UIImage imageNamed:@"icon_place"]];
    self.orderNoLabel.text = [NSString stringWithFormat:@"物流单号：%@", orderModel.shipping_code];
}

- (void)setModel:(HNSH_LogisticsModel *)model{
    _model = model;
    
    self.statusLabel.text = [NSString stringWithFormat:@"物流状态：%@", model.status_desc];
    self.companyLabel.text = [NSString stringWithFormat:@"物流公司：%@", model.com_name];
}

//MARK: Getter Methods
- (UIView *)segView{
    if (!_segView) {
        _segView = [UIView new];
        _segView.backgroundColor = [UIColor colorWithHexString:@"#EDEDED"];
    }
    return _segView;
}

- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
    }
    return _imgView;
}

- (UILabel *)statusLabel{
    if (!_statusLabel) {
        _statusLabel = [UILabel new];
        _statusLabel.font = [UIFont systemFontOfSize:12];
        _statusLabel.textColor = [UIColor appBlack333LabelColor];
    }
    return _statusLabel;
}

- (UILabel *)companyLabel{
    if (!_companyLabel) {
        _companyLabel = [UILabel new];
        _companyLabel.font = [UIFont systemFontOfSize:12];
        _companyLabel.textColor = [UIColor appBlack333LabelColor];
    }
    return _companyLabel;
}

- (UILabel *)orderNoLabel{
    if (!_orderNoLabel) {
        _orderNoLabel = [UILabel new];
        _orderNoLabel.font = [UIFont systemFontOfSize:12];
        _orderNoLabel.textColor = [UIColor appBlack333LabelColor];
    }
    return _orderNoLabel;
}

- (UIView *)secSegView{
    if (!_secSegView) {
        _secSegView = [UIView new];
        _secSegView.backgroundColor = [UIColor colorWithHexString:@"#EDEDED"];
    }
    return _secSegView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textColor = [UIColor appBlack333LabelColor];
        _titleLabel.text = @"订单跟踪";
    }
    return _titleLabel;
}

@end
